package Day2025_03_16;

public class LeetCode673 {
    public int findNumberOfLIS(int[] nums) {
        int n = nums.length;
        int[] dp = new int[n];
        int[] count = new int[n];
        for (int i = 0; i < n; i++) dp[i] = count[i] = 1;
        int relen = 1, recount = 1;
        for (int i = 1; i < n; i++) {
            for (int j = i - 1; j >= 0; j--) {
                if (nums[i] - nums[j] > 0) {
                    if (dp[j] + 1 == dp[i]) count[i] += count[j];
                    if (dp[j] + 1 > dp[i]) {
                        count[i] = count[j];
                        dp[i] = dp[j] + 1;
                    }
                }
            }
            if (relen == dp[i]) recount += count[i];
            if (relen < dp[i]) {
                relen = dp[i];
                recount = count[i];
            }
        }
        return recount;
    }
}
